package com.example.demo.sys.controller;

import com.example.demo.sys.common.JsonData;
import com.example.demo.sys.dto.DeptLevelDto;
import com.example.demo.sys.param.DeptParam;
import com.example.demo.sys.service.SysDeptService;
import com.example.demo.sys.service.SysTreeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by 蔡超 on 2018/10/7.
 */
@RestController
@Slf4j
@RequestMapping("/sys/dept")
public class SysDeptController {

    @Autowired
    private SysDeptService sysDeptService;

    @Autowired
    private SysTreeService treeService;

    @RequestMapping("/save.json")
    public JsonData saveDept(DeptParam deptParam){
        String id = sysDeptService.save(deptParam);
        return JsonData.success(id);
    }

    @RequestMapping("/update.json")
    public JsonData update(DeptParam deptParam){
        int result = sysDeptService.update(deptParam);
        return JsonData.success(result);
    }

    @RequestMapping("/tree.json")
    public JsonData tree(){
        List<DeptLevelDto> list = treeService.deptTree();
        return JsonData.success(list);
    }

}
